package com.edu.edu.day25_homework.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.edu.edu.day25_homework.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * A simple {@link Fragment} subclass.
 */
public class FindFragmen extends Fragment{


//    private MyFindAdapter adapter;
    private ListView mLv;
    private SimpleAdapter adapter;

    public FindFragmen() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_find, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        mLv = (ListView) view.findViewById(R.id.find_list);
        List<Map<String, Object>> data = new ArrayList<>();


        String[] name = getResources().getStringArray(R.array.find);
        int[] imagesId = getImagesId();
        for (int i = 0; i < name.length; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("images", imagesId[i]);
            map.put("text", name[i]);
            data.add(map);
        }

        adapter = new SimpleAdapter(getActivity(), data, R.layout.find_list_item, new String[]{"images", "text"}, new int[]{R.id.find_image, R.id.find_text});

        mLv.setAdapter(adapter);
//        adapter.setViewBinder(new SimpleAdapter.ViewBinder() {
//            @Override
//            public boolean setViewValue(View view, Object o, String s) {
//                int  red = new Random().nextInt(100) * 100;
//                int  green = new Random().nextInt(100) * 100;
//                int  blue = new Random().nextInt(100) * 100;
//                LinearLayout ll_color = (LinearLayout) view.findViewById(R.id.fl_color);
//                ll_color.setBackgroundColor(Color.rgb(red, green, blue));
//                return true;
//            }
//        });
    }



    private int[] getImagesId() {
        return new int[]{R.mipmap.image07,R.mipmap.image08,R.mipmap.image09,R.mipmap.image10,R.mipmap.image11,R.mipmap.image12,R.mipmap.image13,R.mipmap.iamge14,R.mipmap.image15,R.mipmap.image16,R.mipmap.image17,R.mipmap.image18,};
    }

}
